/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package backupit.core.io;

import backupit.core.BackupFactory;
import backupit.core.dirbackup.DirBackup;
import backupit.core.BackupList;
import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author dbotelho
 */
public class SaveBackupList implements Runnable{
    
    private BackupList backupList;
    private XMLEncoder encoder;

    public SaveBackupList(String fileName,BackupList backupList) throws FileNotFoundException{
        super();
        this.backupList = backupList;
        this.encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(fileName)));
    }

    public void run() {
        encoder.writeObject(backupList);
        encoder.close();
    }
/*    
    public static void main(String[] args){
        try {
            DirBackup b = BackupFactory.getDirBackupInstance();
            b.setName("asd");
            BackupList l = new BackupList();
            l.add(b);
            l.add(BackupFactory.getDirBackupInstance("name", "source", "destination", true, false, true, true));
            new Thread(new SaveBackupList("/home/dbotelho/backuplist.xml", l)).start();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(SaveBackupList.class.getName()).log(Level.SEVERE, null, ex);
        }
    }*/
}
